package com.szis.auth.runner;

import jakarta.annotation.Resource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: yxl
 * 2025-07-16
 */

@Component
@Order(1)
public class ConfigPrinter implements CommandLineRunner {

    @Resource
    private Environment environment;

    @Override
    public void run(String... args) {
        System.out.println("===== 所有生效的配置信息 =====");

        ((AbstractEnvironment) environment).getPropertySources().forEach(ps -> {
            if (ps.getSource() instanceof Map) {
                ((Map<?, ?>) ps.getSource()).forEach((key, value) -> {
                    if (key.toString().startsWith("spring") || key.toString().startsWith("sa-token") || key.toString().startsWith("mybatis-plus")) {
                        System.out.println(key + " = " + value);
                    }
                });
            }
        });
    }

}
